<?php
if ($argc < 2 ) {
  die("\n\t\tUsage: " . $argv[0]. "  /path/to/libs/");
}

$libsDir = $argv[1];
if ( $libsDir[strlen($libsDir)-1] != "/" ) $libsDir .= "/";

$finalDest = $libsDir ;

if (is_dir($finalDest)) {
  echo "Found previous installation of drylamp at $finalDest\n";
  if ($argv[2] == "-f") {
    echo "Erasing previous installation\n";
    shell_exec("rm -Rdf ". $finalDest);
  }
   else die("Use -f option to force reinstallation\n");
}

echo "Checking out the source code ...";
$svnCmd = "svn export http://drylamp.googlecode.com/svn/trunk/drylamp " . $libsDir ;
$output = shell_exec($svnCmd);
echo "OK\n";

echo "Setting permissions ...";
shell_exec( "chmod 0777 " . $finalDest. "smarty_ext/cache/"  );
shell_exec( "chmod 0777 ". $finalDest. "smarty_ext/compile/" );
echo "\nPermissions for ".  $finalDest. "smarty_ext/cache/ and ". $finalDest. "smarty_ext/compile/ were set to 0777.\n";
echo "Configure ownership and appropriate permissions as necessary.\n";
echo "OK\n";